<?php

/**
 * 用户是否可以订阅小工具
 * @author top
 *
 */
class wsubscribe extends CWidget {
	
	public $model = null;
	
	private $_subscirbe = false;
	
	/**
	 * (non-PHPdoc)
	 *
	 * @see CWidget::init()
	 */
	public function init() {
		
		$user = Yii::app ()->user;
		$user_id = $user->id;
		
		// 可以订阅
		if (Educators::model ()->canSubscribe ( $this->model->id )) {
			$this->_subscirbe = true;
		} else {
			// 取消订阅
			$this->_subscirbe = false;
		}
	}
	
	/**
	 * (non-PHPdoc)
	 *
	 * @see CWidget::run()
	 */
	public function run() {
		// 可以订阅
		if ($this->_subscirbe) {
			$url = Educators::model ()->getSubscribeUrl ( $this->model->profile->nick );
			echo CHtml::ajaxLink ( '订阅', $url, array ('success'=>'function(Txt){var json = eval(\'Txt\'); if(json.code==200){}}'), array ('class' => 'btn' ) );
		} else {
			// 取消订阅
			$url = Educators::model ()->getUnSubscribeUrl ( $this->model->profile->nick );
			echo CHtml::ajaxLink ( '取消订阅', $url, array (), array ('class' => 'btn' ) );
		}
	
	}
}